/*
 * demo show __thread
 */

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>

static __thread int t_value;

static void *p1_threadFun(void *arg)
{
    int i;
    t_value = 1;
    pthread_detach(pthread_self());
    for (i = 0; i < 10; i++)
    {
        printf("THREAD1:t_value:%d\n", t_value);
        sleep(1);
    }
}
static void *p2_threadFun(void *arg)
{
    int i;
    t_value = 2;
    pthread_detach(pthread_self());
    for (i = 0; i < 10; i++)
    {
        printf("THREAD2:t_value:%d\n", t_value);
        sleep(2);
    }
}

int main()
{
    pthread_t p1, p2;
    if (0 != pthread_create(&p1, NULL, p1_threadFun, NULL))
    {
        perror("create p1\n");
        exit(1);
    }
    if (0 != pthread_create(&p2, NULL, p2_threadFun, NULL))
    {
        perror("create p2\n");
        exit(1);
    }
    printf("create thread done\n");
    while(1);

}